package com.bj58.migrate.model;

import com.bj58.migrate.bll.IdcBll;
import com.bj58.migrate.helper.StringHelper;
import com.bj58.migrate.helper.dao.DatabaseHelper;
import com.bj58.sfft.utility.dao.annotation.Column;
import com.bj58.sfft.utility.dao.annotation.Id;
import com.bj58.sfft.utility.dao.annotation.NotDBColumn;
import com.bj58.sfft.utility.dao.annotation.Table;
import com.bj58.sfft.utility.dao.basedao.DAOHelper;
import com.bj58.sfft.utility.dao.basedao.IPreparedStatementHandler;

/**
 * Created by lvzheng on 2014/8/8.
 */
@Table( name = "t_avgsalary2015_jianzhi" )
public class AvgJZSalaryModel{
	@NotDBColumn
	static final IPreparedStatementHandler handler = new IPreparedStatementHandlerImpl();
	@NotDBColumn
	static DAOHelper daoHelper = DatabaseHelper.getInstance().getDaoHelper();
	@Id
	private Long id;
	@Column( name = "localid" )
    private int localid;
	@Column( name = "cateid" )
    private int cateid;
	@Column( name = "catename" )
    private String catename;
	@Column( name = "localname" )
    private String localname;
	@Column( name = "infocount" )
    private volatile int infocount = 0;
	@Column( name = "avgsalary" )
    private volatile double avg = 0.0;      //保留2位小数
	@Column( name = "count_mianyi" )
    private volatile int count_mianyi = 0;
	@Column( name = "countless_50" )
	private volatile int countless_50 = 0;
	@Column( name = "count50_150" )
	private volatile int count50_150 = 0;
	@Column( name = "count150_250" )
	private volatile int count150_250 = 0;
	@Column( name = "count250_350" )
	private volatile int count250_350 = 0;
	@Column( name = "count350_500" )
	private volatile int count350_500 = 0;
	@Column( name = "count500_1000" )
	private volatile int count500_1000 = 0;
	@Column( name = "countthan_1000" )
	private volatile int countthan_1000 = 0;
	@Column( name = "startdate" )
    private int startdate;
	@Column( name = "enddate" )
	private int enddate;
	@Column( name = "level1" )
	private int level1;
	@Column( name = "jiesuanfangshi" )
	private int jiesuanfangshi;
	@Column( name = "extlong" )
	private Long extlong = 0L;
	@Column( name = "etx" )
	private String ext = "";

    public void info_IncrementAndGet(){
        this.infocount++;
    }

    public void setInterval( String paramValue ){

        if( paramValue != null && paramValue.length() > 0 ){

			Integer salary = StringHelper.tryParseInt( paramValue, 0 );

            if( salary != null ){

                this.info_IncrementAndGet();

				if( salary <= 0 ){
					count_mianyi_IncrementAndGet();
				}
				else if( salary <= 50 ){
					countless_50_IncrementAndGet();
				}
				else if( salary <= 150 ){
					count150_250_IncrementAndGet();
				}
				else if( salary <= 250 ){
					count150_250_IncrementAndGet();
				}
				else if( salary <= 350 ){
					count250_350_IncrementAndGet();
				}
				else if( salary <= 500 ){
					count350_500_IncrementAndGet();
				}
				else if( salary <= 1000 ){
					count500_1000_IncrementAndGet();
                }
				else{
					countthan1000_IncrementAndGet();
				}
            }
        }
    }

    public void count_mianyi_IncrementAndGet(){
        this.count_mianyi++;
    }

	public void countless_50_IncrementAndGet(){

		this.countless_50++;
    }

	public void count50_150_IncrementAndGet(){

		this.count50_150++;
    }

	public void count150_250_IncrementAndGet(){

		this.count150_250++;
    }

	public void count250_350_IncrementAndGet(){

		this.count250_350++;
    }

	public void count350_500_IncrementAndGet(){

		this.count350_500++;
    }

	public void count500_1000_IncrementAndGet(){

		this.count500_1000++;
    }

	public void countthan1000_IncrementAndGet(){

		this.countthan_1000++;
	}

	/**
	 * 日结（默认）平均薪资计算规则
	 */
    public void caculateAvg(){

		int count = this.count50_150 + this.count150_250 + this.count250_350 + this.count350_500;
    	double avg = 0.00;
		if (count > 0) {
			avg = ( this.count50_150 * 100 + this.count150_250 * 200 + this.count250_350 * 300 + this.count350_500 * 425 ) / count;
    	}
        this.avg = avg;
    }

    /**
     * 写入日志或者DB
     * @throws Exception 
     */
    public void write() throws Exception{

		IdcBll idcBll = new IdcBll();
		Long id = idcBll.getId();
		StringBuffer sql = new StringBuffer( "insert into t_avgsalary2015_jianzhi(id,localid,cateid,localname,catename,avgsalary,count_mianyi,countless_50,count50_150,count150_250,count250_350,count350_500,count500_1000,countthan_1000,infocount,startdate,enddate,jiesuanfangshi,level1,etx) values(" ).append( id + "," ).append( this.localid + "," ).append( this.cateid + "," ).append( "'" + this.localname + "'," ).append( "'" + this.catename + "'," ).append( this.avg + "," ).append( this.count_mianyi + "," )
.append( this.countless_50 + "," ).append( this.count50_150 + "," ).append( this.count150_250 + "," ).append( this.count250_350 + "," ).append( this.count350_500 + "," ).append( this.count500_1000 + "," ).append( this.countthan_1000 + "," )
.append( this.infocount + "," ).append( this.startdate + "," )
.append( this.enddate + "," ).append( this.jiesuanfangshi + "," ).append( "0,'" ).append( this.ext ).append( "')" );
		String condition = sql.toString();
		System.out.println( condition );
		daoHelper.execInsert( condition, handler );
    }

    public void show(){

        //System.out.println( "this.infocount:" + this.infocount );
    	System.out.println("##################localid="+this.localid+"cateid="+this.cateid+"catename="+this.catename+""+this.localname+"infocount ="+this.infocount+"avg="
 + this.avg + "count_mianyi=" + this.count_mianyi + "countless_50=" + this.countless_50 + "count50_150=" + this.count50_150 + "count150_250=" + this.count150_250 + "count250_350=" + this.count250_350 + "count350_500=" + this.count350_500 + "count500_1000=" + this.count500_1000 + "countthan_1000:" + this.countthan_1000 + "startdate=" + this.startdate + "enddate:" + this.enddate );
    }

    //-------------------getset-------------------//

	public Long getId(){

		return id;
	}

	public void setId( Long id ){

		this.id = id;
	}

	public int getLocalid(){

		return localid;
	}

	public void setLocalid( int localid ){

		this.localid = localid;
	}

	public int getCateid(){

		return cateid;
	}

	public void setCateid( int cateid ){

		this.cateid = cateid;
	}

	public String getCatename(){

		return catename;
	}

	public void setCatename( String catename ){

		this.catename = catename;
	}

	public String getLocalname(){

		return localname;
	}

	public void setLocalname( String localname ){

		this.localname = localname;
	}

	public int getInfocount(){

		return infocount;
	}

	public void setInfocount( int infocount ){

		this.infocount = infocount;
	}

	public int getCount_mianyi(){

		return count_mianyi;
	}

	public void setCount_mianyi( int count_mianyi ){

		this.count_mianyi = count_mianyi;
	}

	public int getCountless_50(){

		return countless_50;
	}

	public void setCountless_50( int countless_50 ){

		this.countless_50 = countless_50;
	}

	public int getCount50_150(){

		return count50_150;
	}

	public void setCount50_150( int count50_150 ){

		this.count50_150 = count50_150;
	}

	public int getCount150_250(){

		return count150_250;
	}

	public void setCount150_250( int count150_250 ){

		this.count150_250 = count150_250;
	}

	public int getCount250_350(){

		return count250_350;
	}

	public void setCount250_350( int count250_350 ){

		this.count250_350 = count250_350;
	}

	public int getCount350_500(){

		return count350_500;
	}

	public void setCount350_500( int count350_500 ){

		this.count350_500 = count350_500;
	}

	public int getCount500_1000(){

		return count500_1000;
	}

	public void setCount500_1000( int count500_1000 ){

		this.count500_1000 = count500_1000;
	}

	public int getCountthan_1000(){

		return countthan_1000;
	}

	public void setCountthan_1000( int countthan_1000 ){

		this.countthan_1000 = countthan_1000;
	}

	public int getStartdate(){

		return startdate;
	}

	public void setStartdate( int startdate ){

		this.startdate = startdate;
	}

	public int getEnddate(){

		return enddate;
	}

	public void setEnddate( int enddate ){

		this.enddate = enddate;
	}

	public int getLevel1(){

		return level1;
	}

	public void setLevel1( int level1 ){

		this.level1 = level1;
	}

	public int getJiesuanfangshi(){

		return jiesuanfangshi;
	}

	public void setJiesuanfangshi( int jiesuanfangshi ){

		this.jiesuanfangshi = jiesuanfangshi;
	}

	public Long getExtlong(){

		return extlong;
	}

	public void setExtlong( Long extlong ){

		this.extlong = extlong;
	}

	public String getExt(){

		return ext;
	}

	public void setExt( String ext ){

		this.ext = ext;
	}

	public double getAvg(){

		return avg;
	}

}
